package com.example.tliaswebmanagement.service.impl;

import com.example.tliaswebmanagement.entity.PageResult;
import com.example.tliaswebmanagement.entity.Student;
import com.example.tliaswebmanagement.mapper.StudentMapper;
import com.example.tliaswebmanagement.service.StudentService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class StudentServiceImpl implements StudentService {
    private final StudentMapper studentMapper;
    @Autowired
    public StudentServiceImpl(StudentMapper studentMapper) {
        this.studentMapper = studentMapper;
    }
    @Override
    public PageResult findAll(Integer page, Integer pageSize, String name, Integer degree, Integer clazzId) {
        //先设置分页查询
        PageHelper.startPage(page,pageSize);
        //再将查询结果封装到Page里
        List<Student> students = studentMapper.findAll(name,degree,clazzId);
        Page<Student> p=(Page<Student>) students;
        return new PageResult(p.getTotal(),p.getResult());
    }
    @Transactional
    @Override
    public void deleteByIds(List<Integer> ids) {
        studentMapper.deleteByIds(ids);

    }

    @Override
    public Student findById(Integer id) {
        return studentMapper.findById(id);
    }
}
